Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Intermediate »

Table of Contents

Python v3.7 HowTos:

  • ----------------
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Greedy
  • Sort
  • Binary Search
  • Depth First Search [DFS]
  • Breadth First Search [BFS]
  • Binary Search Tree [BST]
  • ----------------
  • Array
  • String
  • Heap
  • Stack
  • Queue
  • Tree
  • Linked List
  • Hash Table
  • Bit Manipulation
  • Two Pointers
  • Math
  • Decorator
  • ----------------
  • Basic
  • Intermediate
  • Advanced
  • Interview
  • ----------------
  • Spark
  • Tkinter
  • Turtle
  • Games
  • Web
  • ----------------
  • About
  • History

Previous topic

Find the type of the progression

Next topic

Find common divisors between two numbers

Quick search

Print the length of the seriesΒΆ

Print the length of the series and the series from the given
3rd term, 3rd last term and the sum of a series.
Input data:
3rd term - 3
3rd last term - 118 55
Sum of the series - 91
tn = int(input("Input third term of the series:"))

tltn = int(input("Input 3rd last term:"))

s_sum = int(input("Sum of the series:"))

n = int(2*s_sum/(tn+tltn))
print("Length of the series: ",n)
d = (tltn-tn)/(n-5)
a = tn-2*d
j = 0

print("Series:")
for j in range(n-1):
    print(int(a), end=" ")
    a += d

print(int(a),end=" ")

Output:

Input third term of the series: 3
Input 3rd last term: 118
Sum of the series: 91
Length of the series:  1
Series:
60

See also

https://www.w3resource.com/python-exercises/basic/python-basic-1-exercise-28.php

Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Intermediate »
© Copyright 2020, Sergiy Zaytsev, szaytsev@hotmail.com. Created using Sphinx 2.3.0.